<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>库存存量指标</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:130px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 130px;}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">分店仓库</label>
							<div class="layui-input-inline">
								<select name="txtBranchNo" lay-filter="branch-select" lay-verify="" lay-search>
									<option value="">请选择...</option>
									{volist name="branchs" id="vo"}
									<option value="{$vo['branch_no']}">{$vo['branch_name']}</option>
									{/volist}
								</select>
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品货号</label>
							<div class="layui-input-inline">
								<input type="text" name="txtItemNo" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品分类</label>
							<div class="layui-input-inline">
								<select name="txtClassNo" lay-verify="" lay-search>
									<option value="">请选择...</option>
									{volist name="cls" id="vo"}
									<option value="{$vo['item_clsno']}">{$vo['item_clsname']}</option>
									{/volist}
								</select>
							</div>
						</div>
						<span style="color:#ff6a08;text-align:left;padding-top:10px;display: inline-block;"> 
								    *先使用"库存调整"功能添加库存记录，才能调整相应数据
						    </span>
						</div>
						<div class="layui-row">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">库存上限</label>
							<div class="layui-input-inline">
								<input type="text" name="txtMaxQty" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">库存下限</label>
							<div class="layui-input-inline">
								<input type="text" name="txtMinQty" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品品牌</label>
							<div class="layui-input-inline">
								<select name="txtBrandNo" lay-verify="" lay-search>
									<option value="">请选择...</option>
									{volist name="brands" id="vo"}
									<option value="{$vo['code_id']}">{$vo['code_name']}</option>
									{/volist}
								</select>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="stockage-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
						</div>
						
					</div>
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body">
				<table id="stockage-table" lay-filter="stockage-table"></table>
			</div>
		</div>

		<script type="text/html" id="stockage-toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增
		    </button>
		    <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-delete"></i>
		        删除
		    </button>
		</script>

		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script>
			var branch_no="";
			layui.use(['table', 'form', 'jquery','common'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;

				let MODULE_PATH = "{:U('products/Probase','','')}/";

				let cols = [
					[{
							type: 'checkbox',
							fixed:"left"
						},
						{
							title: '商品货号',
							field: 'item_no',
							align: 'center',
							width: 120,
							fixed:"left"
						},
						{
							title: '商品名称',
							field: 'item_name',
							align: 'center',
							width: 120
						},
						{
							title: '自编码',
							field: 'item_subno',
							align: 'center',
							width: 120
						},
						{
							title: '仓库编码',
							field: 'branch_no',
							align: 'center',
							width: 120
						},
						{
							title: '仓库名称',
							field: 'branch_name',
							align: 'center',
							width: 120
						},
						{
							title: '库存数量',
							field: 'stock_qty',
							align: 'center',
							width: 120
						},
						{
							title: '库存上限',
							field: 'max_qty',
							align: 'center',
							width: 120
						},
						{
							title: '库存下限',
							field: 'min_qty',
							align: 'center',
							width: 120
						},
						{
							title: '单位',
							field: 'unit_no',
							align: 'center',
							width: 120
						},
						{
							title: '规格',
							field: 'item_size',
							align: 'center',
							width: 120
						},
						{
							title: '类别名称',
							field: 'item_clsname',
							align: 'center',
							width: 120
						},
						{
							title: '类别编码',
							field: 'item_clsno',
							align: 'center',
							width: 120
						}
					]
				]

				table.render({
					elem: '#stockage-table',
					url: MODULE_PATH+"query",
					page: true,
					height:600,
					cols: cols,
					skin: 'line',
					toolbar: '#stockage-toolbar',
					defaultToolbar: []
				});

				table.on('toolbar(stockage-table)', function(obj) {
					if (obj.event === 'add') {
						window.add();
					} else if (obj.event === 'batchRemove') {
						window.batchRemove(obj);
					}
				});

				form.on('submit(stockage-query)', function(data) {
					table.reload('stockage-table', {
						where: data.field
					})
					return false;
				});

				form.on('switch(stockage-enable)', function(obj) {
					layer.tips(this.value + ' ' + this.name + '：' + obj.elem.checked, obj.othis);
				});

				form.on('select(branch-select)', function(data){
					  branch_no=data.value;
				});
				
				window.add = function() {
					window.location.href=MODULE_PATH+"stockageInput";
				}

				window.batchRemove = function(obj) {
					
					var checkIds = common.checkField(obj,'item_no');
					if(branch_no==''){
						layer.msg("请选择分店仓库", {
							icon: 2,
							time: 1000
						});
						return false;
					}
					if (checkIds === "") {
						layer.msg("未选中数据", {
							icon: 3,
							time: 1000
						});
						return false;
					}
					
					layer.confirm('确定要删除记录?', {
						icon: 3,
						title: '提示'
					}, function(index) {
						layer.close(index);
						let loading = layer.load();
						$.ajax({
							url: MODULE_PATH + "stockageDelete",
							data:{"branch_no":branch_no,"items":checkIds},
							dataType: 'json',
							type: 'post',
							success: function(result) {
								layer.close(loading);
								if (result.code) {
									layer.msg(result.msg, {
										icon: 1,
										time: 1000
									}, function() {
										table.reload('stockage-table');
									});
								} else {
									layer.msg(result.msg, {
										icon: 2,
										time: 1000
									});
								}
							}
						})
					});
				}

				window.refresh = function(param) {
					table.reload('stockage-table');
				}
			})
		</script>
	</body>
</html>
